package jmine.tec.report.cell.impl;

import java.io.Serializable;
import java.util.Date;

import jmine.tec.report.cell.DataCell;

/**
 * @author takeshi
 */
public abstract class AbstractDoubleValueDataCell implements DataCell, Serializable {

    /**
	 * 
	 */
    private static final long serialVersionUID = 3968150121921966182L;

    private final Double number;

    /**
     * @param value the value
     */
    public AbstractDoubleValueDataCell(final Double value) {
        super();
        this.number = value;
    }

    /**
     * @param value the value
     */
    public AbstractDoubleValueDataCell(final double value) {
        this(Double.valueOf(value));
    }

    /**
     * @return {@link Date}
     */
    public final Date toDate() {
        return null;
    }

    /**
     * Returns as a raw double
     * 
     * @return {@link Double}
     */
    public final Double toDouble() {
        return this.number;
    }

    /**
     * @param o {@link DataCell}
     * @return int
     */
    public int compareTo(final DataCell o) {
        if (!(o instanceof AbstractDoubleValueDataCell)) {
            return 1;
        }
        AbstractDoubleValueDataCell other = (AbstractDoubleValueDataCell) o;
        if (this.number == null) {
            if (other.number == null) {
                return 0;
            } else {
                return -1;
            }
        }
        if (other.number == null) {
            return 1;
        }
        return this.number.compareTo(other.number);
    }

    /**
     * @return {@link String}
     */
    @Override
    public String toString() {
        return "" + this.number;
    }

    /**
     * @return int
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.number == null) ? 0 : this.number.hashCode());
        return result;
    }

    /**
     * @param obj {@link Object}
     * @return boolean
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        final AbstractDoubleValueDataCell other = (AbstractDoubleValueDataCell) obj;
        if (this.number == null) {
            if (other.number != null) {
                return false;
            }
        } else if (!this.number.equals(other.number)) {
            return false;
        }
        return true;
    }

}
